<?php

class Home extends Controller {

	//function __construct()
        function Home()
        {
                parent::Controller();
                $this->load->model('test_model');
                $this->load->library('form_validation');
        }

        function Index()
	{
            	//Loads the main page
            $this->load->view('home/index');
        }

        function Register()
	{
            	//Check if the Registration form was submitted

            $this->load->library('form_validation');

            if ($this->input->post('submit_user'))
            {
                //Validate & Prep
                $this->form_validation->set_rules('first_name', 'firstname field', 'trim|required|max_length[15]');
                $this->form_validation->set_rules('last_name', 'lastname field', 'trim|required|max_length[15]');
                $this->form_validation->set_rules('email', 'email field', 'trim|required|max_length[50]');
                $this->form_validation->set_rules('username', 'username field', 'trim|required|max_length[15]');
                $this->form_validation->set_rules('password', 'password field', 'trim|required|max_length[15]');

                $result = $this->form_validation->run();

                if ($result == TRUE)
                {
                    //echo "<p>You have successfully registered!</p>";
                    $this->load->model('test_model');

                    $result = $this->test_model->add_user($_POST['first_name'], $_POST['last_name'], $_POST['email'], $_POST['username'], $_POST['password']);

                        if ($result === TRUE)
                            redirect('user/usermain');
                        else
                            "<p></p>";

                }
                    else
                        {
                            echo "<p>It failed.</p>";
                            echo "There were errors with your registration";
                            //echo "<p>" . validation_errors() . "</p>";
                        }
                }

                $this->load->view('home/register');
	}
}

/* EOF */